Skip to content

Align Falcon H1 with upstream MLX inference - #331

Merged
davidkoski merged 1 commit into
ml-explore:mainfrom
aleroot:falconh1-improvments
Jun 11, 2026
Merged

davidkoski merged 1 commit into
ml-explore:mainfrom
aleroot:falconh1-improvments

Conversation

@aleroot

@aleroot aleroot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

Update Falcon H1/H1R inference behavior to match current mlx-lm more closely.

This fixes tied embedding output projection and scaling, routes attention through the common cache-aware causal path, advances Mamba cache metadata during generation, reports per-layer KV head counts correctly, and chunks SSM prefill to reduce long-prompt memory and latency.

Also mirror upstream ArraysCache length handling for hybrid and batched paths: preserve left padding and lengths through filter, extend, copy, and serialization; forward length preparation through CacheList; and use per-row lengths in Falcon H1 convolution plus chunked SSM state updates.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

Comment thread Libraries/MLXLLM/Models/SSM.swift Resolved
Comment thread Libraries/MLXLLM/Models/SSM.swift Resolved
Update Falcon H1/H1R inference behavior to match current mlx-lm more closely.

This fixes tied embedding output projection and scaling, routes attention through the common cache-aware causal path, advances Mamba cache metadata during generation, reports per-layer KV head counts correctly, and chunks SSM prefill to reduce long-prompt memory and latency.

Also mirror upstream ArraysCache length handling for hybrid and batched paths: preserve left padding and lengths through filter, extend, copy, and serialization; forward length preparation through CacheList; and use per-row lengths in Falcon H1 convolution plus chunked SSM state updates.

Add regression coverage for the shared causal attention mask path, SSM mask metadata, nested hybrid cache length propagation, and Mamba metadata copy behavior.
@aleroot
aleroot force-pushed the falconh1-improvments branch from e09123a to 95dbbf5 Compare June 11, 2026 01:25

@davidkoski davidkoski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@davidkoski
davidkoski merged commit 771e4ee into ml-explore:main Jun 11, 2026
2 checks passed
mdstaff added a commit to mdstaff/mlx-swift-lm that referenced this pull request Jun 12, 2026
…emma-4-12b-local-validation

Brings in ml-explore#308 (Gemma 4 MTP speculative decoding, e145aca), ml-explore#333 (cross-
layer KV sharing in no-cache forward), ml-explore#337 (prepare() windowSize), ml-explore#331,
ml-explore#332. Conflict resolutions:
- LMInput.ProcessedAudio: keep features/mask shape (consumed by
  Gemma4Unified); main's samples variant had no constructors.
- Gemma4TextBackbone/Gemma4TextLanguageModel: union of ml-explore#327's tokenTypeIds
  and ml-explore#308's emitDrafterState threading; tuple return from ml-explore#308.
- Gemma4.prepare image path: keep single full-sequence forward with
  tokenTypeIds (bidirectional vision overlay can't span chunk boundaries);
  main's chunked text-only prefill retained.
- Dropped hasExplicitCache gating orphaned by ml-explore#333.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dkgv pushed a commit to dkgv/mlx-swift-lm that referenced this pull request Jul 30, 2026
Update Falcon H1/H1R inference behavior to match current mlx-lm more closely.

This fixes tied embedding output projection and scaling, routes attention through the common cache-aware causal path, advances Mamba cache metadata during generation, reports per-layer KV head counts correctly, and chunks SSM prefill to reduce long-prompt memory and latency.

Also mirror upstream ArraysCache length handling for hybrid and batched paths: preserve left padding and lengths through filter, extend, copy, and serialization; forward length preparation through CacheList; and use per-row lengths in Falcon H1 convolution plus chunked SSM state updates.

Add regression coverage for the shared causal attention mask path, SSM mask metadata, nested hybrid cache length propagation, and Mamba metadata copy behavior.
div0-space pushed a commit to LibraxisAI/mlx-swift-lm that referenced this pull request Nov 29, 2026
…l-explore#331)

* Add an opt-in plain-chunk ceiling for bidirectional media requests

`CBv2SchedulerConfig.bidirectionalMediaPrefillChunkCeiling` (nil by default)
caps the plain prefill chunk of a request whose multimodal input carries
bidirectional blocks. A paged span-bearing chunk attends in one unblocked
call, so its score tensor grows with the chunk length times the history;
the ceiling lets a host widen text chunks without widening that tensor.

Both chunk-cap sites in SchedulerV2 (the ordinary plan and the deferred
block-row admission) read `plainPrefillChunkSize(hasBidirectionalBlocks:)`.
A chunk that begins at a block still extends over the whole block, the
solo stripe still never arms for these requests, and causal media keeps
`prefillChunkSize`. First-token projection already refuses to price
block-bearing rows (`multimodalWork`), so it needs no mirror.

Unit tests cover the ceiling beside a wide text chunk, block snap-over,
unset and non-binding values, causal media, deferred admission and
serialized prefill beside decode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Move the media chunk ceiling tests into the Scheduling unit folder

SDK main keeps scheduler unit tests in Tests/MLXLMTests/Unit/Scheduling
(CBv2PrefillInterleaveTests). Use the same folder so the merge does not leave
a parallel Unit/Scheduler directory. No test or code change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
div0-space pushed a commit to LibraxisAI/mlx-swift-lm that referenced this pull request Nov 29, 2026
Brings ml-explore#322 (Flint), ml-explore#324, ml-explore#326-ml-explore#330 (CBv2 paged/MTP/SDPA, GPT-OSS), ml-explore#325 and the
Nemotron Super fused MTP verify window: SDK main up to the commit d-inference
master pins (889fe3c). Main's later ml-explore#331/ml-explore#332 are left out until the provider
adopts ml-explore#332's streamed tool-call type. Package.swift pins the cluster
mlx-swift 9fe34405 instead of main's 67dc7528; that was the only conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants